package com.kindness.frate.fragment;


import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.kindness.frate.R;
import com.kindness.frate.pull.PullRefreshRecyclerView;
import com.kindnesslibrary.adapter.CommonAdapter;
import com.kindnesslibrary.adapter.ViewHolder;
import com.kindnesslibrary.banner.Banner;
import com.kindnesslibrary.banner.GlideImageLoader;
import com.kindnesslibrary.banner.listener.OnBannerListener;
import com.kindnesslibrary.banner.transformer.TabletTransformer;
import com.kindnesslibrary.banner.transformer.ZoomOutSlideTransformer;
import com.kindnesslibrary.fragment.BaseFragment;
import com.kindnesslibrary.fragment.BasePageFragment;
import com.kindnesslibrary.util.EnableLinearManager;
import com.kindnesslibrary.util.ToastUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * 首页
 */
public class MainFragment extends BaseFragment {

    private PullRefreshRecyclerView rv_content;
    private List<String> datas = new ArrayList<>();
    CommonAdapter commonAdapter;

    public static MainFragment newInstance(){
        MainFragment mainFragment = new MainFragment();
        return mainFragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main_layout;
    }

    @Override
    protected void initWidget(View rootView) {
        rv_content = getViewById(R.id.rv_content);
        EnableLinearManager enableLinearManager = new EnableLinearManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        rv_content.setLayoutManager(enableLinearManager);
    }

    @Override
    protected void initData() {
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
        datas.add("");
    }

    @Override
    protected void bindEven() {
        commonAdapter = new CommonAdapter<String>(getActivity(), R.layout.fragment_home_layout, datas){
            @Override
            public void convert(ViewHolder holder, String s) {

            }
        };
        commonAdapter.addHeaderView(addBanner());
        rv_content.setAdapter(commonAdapter);
        commonAdapter.notifyDataSetChanged();
    }

    private View addBanner(){
        View headerView = getActivity().getLayoutInflater().inflate(R.layout.layout_banner_header, null);
        Banner b_banner_header = (Banner) headerView.findViewById(R.id.b_banner_header);
        List<String> banners = Arrays.asList(getActivity().getResources().getStringArray(R.array.url));
        b_banner_header.setImages(banners)
                .setImageLoader(new GlideImageLoader())
                .setOnBannerListener(position -> {

                })
                .start();
        b_banner_header.setPageMargin((int) getResources().getDimension(R.dimen.width_2_80));
        b_banner_header.setBannerAnimation(ZoomOutSlideTransformer.class);
        return headerView;
    }

    @Override
    protected void handlerMessage(Message msg) {

    }

}
